package com.shengqi.xinnongren.work.ui.goods.activities;

import android.content.Context;
import android.content.Intent;
import android.support.design.widget.TabLayout;
import android.support.v4.app.Fragment;
import android.support.v4.view.ViewPager;
import android.widget.RatingBar;
import android.widget.TextView;

import com.shengqi.xinnongren.R;
import com.shengqi.xinnongren.common.adapter.GeneralFragmentPagerAdapter;
import com.shengqi.xinnongren.common.base.BaseMvpActivity;
import com.shengqi.xinnongren.work.ui.goods.fragments.BrowseCommentFragment;
import com.shengqi.xinnongren.work.ui.goods.model.CommentDesc;
import com.shengqi.xinnongren.work.ui.goods.presenter.GoodsCommentPresenter;
import com.shengqi.xinnongren.work.ui.goods.view.GoodsCommentView;

import java.util.ArrayList;
import java.util.List;

import butterknife.BindView;

/**
 * 商品评价
 */
public class GoodsCommentActivity extends BaseMvpActivity<GoodsCommentView, GoodsCommentPresenter> implements GoodsCommentView {
    private static final String EXTRA_GOODS_ID = "goods_id";
    @BindView(R.id.tl_type)
    TabLayout mTabLayout;

    @BindView(R.id.vp_comment)
    ViewPager mViewPager;
    @BindView(R.id.tv_goods)
    TextView mTvGoods;
    @BindView(R.id.tv_service)
    TextView mTvService;
    @BindView(R.id.rb_goods)
    RatingBar mRbGoods;
    @BindView(R.id.rb_service)
    RatingBar mRbService;

    String mGoodsId;

    public static void start(Context context, String goodsId) {
        Intent intent = new Intent(context, GoodsCommentActivity.class);
        intent.putExtra(EXTRA_GOODS_ID, goodsId);
        context.startActivity(intent);
    }

    @Override
    protected int setContentLayoutRes() {
        return R.layout.activity_goods_comment;
    }

    @Override
    protected void initView() {
    }

    @Override
    protected void initData() {
        mGoodsId = getIntent().getStringExtra(EXTRA_GOODS_ID);
        getData();
    }

    private void getData() {
        mPresenter.getCommentHeadInfo(mGoodsId);
    }

    @Override
    protected GoodsCommentPresenter createPresenter() {
        return new GoodsCommentPresenter();
    }

    @Override
    public void onGetCommentHeadInfoSucceed(CommentDesc commentDesc) {
        List<String> stringList = new ArrayList<>();
//        mTvService.setText(String.format("%s分", commentDesc.getServiceScore()));
//        mRbService.setRating(commentDesc.getServiceScore());
        mTvGoods.setText(String.format("%s分", commentDesc.avgScore));
        mRbGoods.setRating(commentDesc.avgScore);
        stringList.add(String.format("全部(%s)", commentDesc.allValuation));
        stringList.add(String.format("晒图(%s)", commentDesc.havePic));
        List<Fragment> fragmentList = new ArrayList<>();
        fragmentList.add(BrowseCommentFragment.newInstance(mGoodsId, BrowseCommentFragment.TYPE_ALL));
        fragmentList.add(BrowseCommentFragment.newInstance(mGoodsId, BrowseCommentFragment.TYPE_PIC));
        mViewPager.setAdapter(new GeneralFragmentPagerAdapter(getSupportFragmentManager(), fragmentList, stringList));
        mTabLayout.setupWithViewPager(mViewPager);
    }

    @Override
    public void showLoadingView() {

    }

    @Override
    public void hideLoadingView() {

    }

    @Override
    public void onNetworkError() {

    }
}
